#include <stdio.h>
#include <string.h>

int main()
{
    char buffer[] = "welcome  to   nan    vj    ing.   ";
    int length = strlen(buffer);
    int idx = 0;
    int pos = 0;
    while (buffer[idx] == ' ')
    {
        idx++;
    }
    for (; idx < length; idx++)
    {
        if (buffer[idx] != ' ')
        {
            buffer[pos] = buffer[idx];
            pos++;
        }
        else if (buffer[idx + 1] != ' ' && buffer[idx + 1] != '\0')
        {
            buffer[pos] = ' ';
            pos++;
        }
    }

    buffer[pos] = '\0';
    printf("%s\n", buffer);
    return 0;
}
